﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geodatabase;

namespace SZ
{
    class ConnectSDE
    {
        IPropertySet pSdePropertySet = new PropertySetClass();

        public ConnectSDE()
        {
            
            string server = "192.168.0.252";
            string instance = "5151";
            string service = "5151";
            string database = "";
            string user = "sde";
            string password = "sde123";
            string version = "SDE.DEFAULT";

            pSdePropertySet.SetProperty("server", server);
            pSdePropertySet.SetProperty("instance", instance);
            pSdePropertySet.SetProperty("service", service);
            pSdePropertySet.SetProperty("database", database);
            pSdePropertySet.SetProperty("user", user);
            pSdePropertySet.SetProperty("password", password);
            pSdePropertySet.SetProperty("version", version);

        }
        public IWorkspace SdeWorkspace()
        {
            try
            {
                IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
                IWorkspace pWorkspace = pWorkspaceFactory.Open(pSdePropertySet, 0);
                return pWorkspace;
            }
            catch
            {
                MessageBox.Show("连接数据库错误！");
                return null;
            }
        }

    }
}
